1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 package net.sf.pmr.agilePlanning.data.iteration;
37
38 import java.util.Date;
39 import java.util.HashSet;
40 import java.util.Iterator;
41 import java.util.List;
42 import java.util.Set;
43
44 import net.sf.pmr.agilePlanning.domain.iteration.Iteration;
45 import net.sf.pmr.agilePlanning.domain.iteration.IterationImpl;
46
47 import org.springframework.dao.support.DataAccessUtils;
48 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
49
50 /***
51 * @author Arnaud Prost (arnaud.prost@gmail.com)
52 */
53 public class IterationMapperImpl extends HibernateDaoSupport implements IterationMapper {
54
55 /***
56 * @see net.sf.pmr.keopsframework.data.EntityMapper#findById(int)
57 */
58 public Object findById(final int id) {
59
60 return getHibernateTemplate().get(IterationImpl.class,
61 new Integer(id));
62
63 }
64
65 /***
66 * @see net.sf.pmr.keopsframework.data.DomainObjectRootAggregateMapper#addOrUpdate(java.lang.Object)
67 */
68 public void addOrUpdate(final Object iteration) {
69
70 Iteration iterationToAddOrUpdate = (Iteration) iteration;
71
72
73
74
75 if (iterationToAddOrUpdate.getRelease() != null && iterationToAddOrUpdate.getRelease().getPersistanceId() == 0) {
76 iterationToAddOrUpdate.setRelease(null);
77 }
78
79 getHibernateTemplate().saveOrUpdate(iterationToAddOrUpdate);
80
81 }
82
83 /***
84 * @see net.sf.pmr.keopsframework.data.DomainObjectRootAggregateMapper#delete(java.lang.Object)
85 */
86 public void delete(final Object iteration) {
87
88 getHibernateTemplate().delete((Iteration) iteration);
89
90 }
91
92 /***
93 * @see net.sf.pmr.agilePlanning.data.iteration.IterationMapper#findByProjectPersistanceId(int)
94 */
95 public Set findByProjectPersistanceId(final int projetPersistanceId) {
96
97 List list = getHibernateTemplate()
98 .find(
99 "from net.sf.pmr.agilePlanning.domain.iteration.IterationImpl iteration where iteration.BasicProject.PersistanceId = ?",
100 new Integer(projetPersistanceId));
101
102 Set setToReturn = new HashSet();
103
104 for (Iterator iterator = list.iterator(); iterator.hasNext();) {
105 Iteration iteration = (Iteration) iterator.next();
106
107 setToReturn.add(iteration);
108
109 }
110
111 return setToReturn;
112
113 }
114
115 /***
116 * @see net.sf.pmr.agilePlanning.data.iteration.IterationMapper#findByProjectPersistanceIdAndByDate(int, java.util.Date)
117 */
118 public Iteration findByProjectPersistanceIdAndByDate(final int projectPersistanceId, final Date date) {
119
120 List list = getHibernateTemplate()
121 .findByNamedParam(
122 "from net.sf.pmr.agilePlanning.domain.iteration.IterationImpl iteration where iteration.BasicProject.PersistanceId = :persistanceId" +
123 " and :date between iteration.Start and iteration.End",
124 new String[] {"persistanceId", "date"},
125 new Object[] {new Integer(projectPersistanceId), date});
126
127 Iteration IterationToReturn = (Iteration) DataAccessUtils.uniqueResult(list);
128
129 return IterationToReturn;
130
131 }
132 }